<?php
/* 
 * class.index.php
 * 我的城市首页
 * @author samuel
 * @date 2009-05-22
 */
include_once 'class.mycityBase.php';
class mycity_index extends mycityBase {

    function  __construct($core) {
        parent::__construct();

        //参数处理
	    $this->step = $this->params['step'] ? strtolower(trim($core->params['step'])) : 'index';
	    $this->seller_id = $this->params['sid'] ? (int)$this->params['sid'] : 0;
	    $this->user_id = $this->params['uid'] ? (int)$this->params['uid'] : 0;
	    $this->type = $this->params['type'] ? strtolower(trim($this->params['type'])) : 'all';
	    $this->stype = $this->params['stype'] ? strtolower(trim($this->params['stype'])) : 'all';
	    $this->settype = $this->params['settype'] ? strtolower(trim($this->params['settype'])) : 'all';
	    if(!$this->user_id){
		    $this->error = "用户ID不合法！";
		    $this->jumpError();
		    exit;
	    }
        $this->run();
    }

    function run(){
    	//WAP页面
	    //header("Content-type: text/vnd.wap.wml");
	    //TITLE
	    $page_title = "我的城市";
	    $content = "";
	    $content .= "<a href='".$_SERVER['PHP_SELF']."?uid=".$this->user_id."&amp;type=all' alt='优惠'>优惠</a>|<a href='".$_SERVER['PHP_SELF']."?uid=".$this->user_id."&amp;type=favor' alt='收藏'>收藏</a>|<a href='".$_SERVER['PHP_SELF']."?uid=".$this->user_id."&amp;type=latest' alt='最新'>最新</a><br/>";
	    //优惠信息（3条，按时间排序）
	    $sellerBase = $this->core->load('seller::sellerBase');
	    $arr_filter = array();
	    $arr_filter[] = array('attr'=>'SellerMsgIs', 'value'=>'1');
	    $arr_limit = array('page'=>1, 'pagesize'=>3, 'url'=>'');
	    if($this->type == 'all' || $this->type=='latest'){
	        $arr_info = $sellerBase->getSellerDiscountList($arr_filter, array("SellerMsgTime"=>"desc"), $arr_limit);
	    }elseif($this->type=='favor'){
	        $favorSellers = $this->core->load('myhome::myhomeBase')->getUserFavorites($this->user_id);
	        $arr_favors = array();
	        if($favorSellers){
	            foreach($favorSellers as $favor){
	                $arr_favors[] = $favor['SellerID'];
	            }
	        }
	        $str_favors = @implode(',', $arr_favors);
	        $sql = "SELECT a.`SellerDisID`, a.`SellerMsg`, a.`SellerMsgIs`, a.`SellerMsgTime`, b.`SellerNameCN` FROM `fun_seller_discount` as a LEFT JOIN `fun_seller` as b ON a.`SellerID`=b.`SellerID` WHERE 1 AND a.`SellerMsgIs` = '1' AND a.`SellerID` IN (".$str_favors.") ORDER BY a.`SellerMsgTime` desc LIMIT 0,3";
	        $discs = $this->core->db->get_results($sql);
	        if(!empty($discs)){
	            $arr_sellerDiscs = array();
                foreach($discs as $disc){
                    $arr_sellerDiscs[] = array(
                        'SellerDisID' => $disc->SellerDisID,
                        'SellerMsg' => $disc->SellerMsg,
                        'SellerMsgIs' => $disc->SellerMsgIs,
					    'SellerNameCN' => $disc->SellerNameCN,
					    'SellerMsgTime' => $disc->SellerMsgTime
                    );
                }
            }
            $arr_info['list'] = $arr_sellerDiscs;
	    }
	    
	    if(is_array($arr_info['list'])){
	        foreach($arr_info['list'] as $info){
		    $content .= "<img src='' alt='优惠图标' /><a href='".$_SERVER['PHP_SELF']."?act=discountshow&amp;type=".$this->type."&amp;uid=".$this->user_id."&amp;id=".$info['SellerDisID']."' alt=''>".$info['SellerMsg']."</a><br/>";
	        }
	    }
	    $content .= "<a href='".$_SERVER['PHP_SELF']."?act=discountlist&amp;type=".$this->type."&amp;uid=".$this->user_id."' alt='更多优惠信息'>更多</a><br/>";
	    //套餐信息（3条，按时间排序）
	    $content .= "<a href='".$_SERVER['PHP_SELF']."?uid=".$this->user_id."&amp;settype=all' alt='个性'>个性</a>|<a href='".$_SERVER['PHP_SELF']."?uid=".$this->user_id."&amp;settype=latest' alt='最新'>最新</a>|<a href='".$_SERVER['PHP_SELF']."?uid=".$this->user_id."&amp;settype=hot' alt='最热'>最热</a><br/>";
	    if($this->settype == 'all' || $this->settype=='latest'){
	        $arr_orderby = array("SetTime"=>"desc");
	    }elseif($this->settype == 'hot'){
	        $arr_orderby = array("Hits"=>"desc");
	    }
	    $arr_filter = array();
	    $arr_filter[] = array('attr'=>'IsSet', 'value'=>'1');
	    $arr_limit = array('page'=>1, 'pagesize'=>3, 'url'=>'');
	    $arr_info = $sellerBase->getInfoList(array('table'=>'fun_seller_set', 'primary'=>'SellerSetID'), "", $arr_filter, $arr_orderby, $arr_limit);
	    if(is_array($arr_info['list'])){
	        foreach($arr_info['list'] as $info){
		    $content .= "<img src='' alt='' /><a href='./mycity.php?act=setinfo&amp;sid=".$info['SellerSetID']."&amp;uid=".$this->user_id."' alt=''>".$info['SellerSetNam']."</a><br/>";
	        }
	    }
	    $content .= "<a href='".$_SERVER['PHP_SELF']."?act=setlist&amp;settype=".$this->settype."&amp;uid=".$this->user_id."' alt='更多套餐信息'>更多</a><br/>";

        $userCustomeInfo = $this->core->load('myhome::myhomeBase')->getUserCustomeInfo($this->user_id);
	    //商家大类
	    if($userCustomeInfo['CustomtypeIs']){
	        $Customtype = $userCustomeInfo['Customtype'];
	        if($Customtype){
	            $arr_cids = explode(',', $Customtype);
	            $i = 1;
	            foreach($arr_cids as $cid){
	                if($i > 3) break;
	                $cate = $this->core->load('seller::sellerBase')->getSellerCateInfo($cid);
	                $content .= "<a href='".$_SERVER['PHP_SELF']."?act=sellerlist&stype=".$this->stype."&amp;uid=".$this->user_id."&amp;type=topclass&amp;cid=".$cate['SellerClassID']."'>".$cate['SellerClassName']."</a>|";
	                $i++;
	            }
	        }
	    }
        $content .= "<br/>";
	    //地区
	    if($userCustomeInfo['CustomqyIs']){
	        $Customqy = $userCustomeInfo['Customqy'];
	        if($Customqy){
	            $arr_ids = explode(',', $Customqy);
	            $i = 1;
	            foreach($arr_ids as $id){
	                if($i > 3) break;
	                $info = $this->core->load('seller::sellerBase')->getSellerAreaInfo($id);
	                $content .= "<a href='".$_SERVER['PHP_SELF']."?act=sellerlist&stype=".$this->stype."&amp;uid=".$this->user_id."&amp;type=area&amp;aid=".$info['SellerAreaID']."'>".$info['SellerAreaNameCN']."</a>|";
	                $i++;
	            }
	        }
	    }
	    $content .= "<br/>";
	    //商圈
	    if($userCustomeInfo['CustomsqIs']){
	        $Customsq = $userCustomeInfo['Customsq'];
	        if($Customsq){
	            $arr_ids = explode(',', $Customsq);
	            $i = 1;
	            foreach($arr_ids as $id){
	                if($i > 3) break;
	                $info = $this->core->load('seller::sellerBase')->getSellerCBDInfo($id);
	                $content .= "<a href='".$_SERVER['PHP_SELF']."?act=sellerlist&stype=".$this->stype."&amp;uid=".$this->user_id."&amp;type=cbd&amp;cid=".$info['SellerCBDID']."'>".$info['SellerCBDNameCN']."</a>|";
	                $i++;
	            }
	        }
	    }
	    $content .= "<br/>";
	    //餐饮类
	    if($userCustomeInfo['CustomCytypeIs']){
	        $CustomCytype = $userCustomeInfo['CustomCytype'];
	        if($CustomCytype){
	            $arr_ids = explode(',', $CustomCytype);
	            $i = 1;
	            foreach($arr_ids as $id){
	                if($i > 3) break;
	                $info = $this->core->load('seller::sellerBase')->getSellerCateInfo($id);
	                $content .= "<a href='".$_SERVER['PHP_SELF']."?act=sellerlist&stype=".$this->stype."&amp;uid=".$this->user_id."&amp;type=cyclass&amp;cid=".$cate['SellerClassID']."'>".$info['SellerClassName']."</a>|";
	                $i++;
	            }
	        }
	    }
	    $content .= "<br/>";
	    //搜索
	    $content .= "<input type='text' name='searchkeyword' value='' maxlength='20' size='15' />";
	    $content .= "<anchor title=\"搜索\">搜<go href=\"./search.php\" method=\"post\">
		        <postfield name=\"type\" value=\"city\" />
		        <postfield name=\"searchkeyword\" value=\"$(searchkeyword)\" />
		        </go></anchor><br/>";
	    //商家
	    $content .= "<a href='".$_SERVER['PHP_SELF']."?stype=all&amp;uid=".$this->user_id."' alt='商家'>商家</a>|<a href='".$_SERVER['PHP_SELF']."?stype=hot&amp;uid=".$this->user_id."' alt='最热'>最热</a>|<a href='".$_SERVER['PHP_SELF']."?stype=latest&amp;uid=".$this->user_id."' alt='最新'>最新</a><br/>";
	    $arr_filter = array();
	    $arr_filter[] = array('attr'=>'Del', 'value'=>'0');
	    $arr_limit = array('page'=>1, 'pagesize'=>5, 'url'=>'');
	    if($this->stype == 'all' || $this->stype == 'latest'){
	        $arr_orderby = array("SellerID"=>"desc");
	    }elseif($this->stype == 'hot'){
	        $arr_orderby = array("SellerHits"=>"desc");
	    }
	    $arr_info = $sellerBase->getInfoList(array('table'=>'fun_seller', 'primary'=>'SellerID'), "", $arr_filter, $arr_orderby, $arr_limit);
	    if(is_array($arr_info['list'])){
	        foreach($arr_info['list'] as $info){
		    $content .= "<img src='' alt='' /><a href='./mycity.php?act=sellerinfo&amp;uid=".$this->user_id."&amp;sid=".$info['SellerID']."' alt=''>".$info['SellerNameCN']."</a><br/>";
	        }
	    }
	    $content .= "<a href='".$_SERVER['PHP_SELF']."?act=sellerlist&amp;stype=".$this->stype."&amp;uid=".$this->user_id."' alt='更多商家信息'>更多</a><br/>";
	    $content .= "<a href='' alt='发布商家'>发布商家</a><br/><br/>";
	    $content .= "<a href='' alt='建议帮助'>建议帮助</a>";



	    $this->core->tpl->assign('content', $content);
	    $this->core->tpl->assign('page_title', $page_title);
	    $this->core->tpl->display('comm.wml');
    
    }
}


?>
